package com.yi;

import org.apache.commons.collections.Transformer;

import java.io.Serializable;
import java.lang.reflect.Method;

//InvokerTransformer类主要代码
public class InvokerTransformer implements Transformer, Serializable {
    private final String iMethodName;
    private final Class[] iParamTypes;
    private final Object[] iArgs;


    // 构造函数
    public InvokerTransformer(String iMethodName, Class[] iParamTypes, Object[] iArgs) {
        this.iMethodName = iMethodName;
        this.iParamTypes = iParamTypes;
        this.iArgs = iArgs;
    }

    // 构造 Transformer 方法
    @Override
    public Object transform(Object input) {
        if (input == null) {
            return null;
        }
        try {
            Class cla = input.getClass();
            Method method = cla.getMethod(iMethodName, iParamTypes);
            return method.invoke(input, iArgs);
        } catch (Exception e) {

        }
        return null;
    }

}